<?php
/**
 * Created by PhpStorm.
 * User: zhangrxiang
 * Date: 2017/1/3
 * Time: 11:37
 */

//implode — 将一个一维数组的值转化为字符串

//string implode ( string $glue , array $pieces )
//string implode ( array $pieces )

$array = ['lastname', 'email', 'phone'];
$comma_separated = implode(",", $array);
echo $comma_separated.PHP_EOL; // lastname,email,phone

// Empty string when using an empty array:
var_dump(implode('hello', [])); // string(0) ""

$array = array(
	"name" => "John",
	"surname" => "Doe",
	"email" => "j.doe@intelligence.gov"
);

// build query...
$sql  = "INSERT INTO table";
// implode keys of $array...
$sql .= " (`".implode("`, `", array_keys($array))."`)";
// implode values of $array...
$sql .= " VALUES ('".implode("', '", $array)."') ";
echo $sql.PHP_EOL;
